var app = getApp(),
  $ = require("../../utils/httpHelper.js")
Page({
  data: {
    height:0,
    money:0,
    list:[],
    showeditdialog:false
  },
  onShareAppMessage: function (res) {
    app.shareApp(res)
  },
  onLoad: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({ height: res.windowHeight-136 })
      }
    })
    let params = {
      rd_session: app.globalData.userInfo.rd_session,
    }
    $.httpPost("recharge_card", params, (data, err) => {
      this.setData({
        money: data.data.balance,
        list:data.data.list
      })

    })
    
  },
  chongz(e){
    var id = e.target.dataset.id
    this.chongz2(id)
  },
  chongz2(id){
    let param = {
      rd_session: app.globalData.userInfo.rd_session,
    }
    $.httpPost("check_pass", param, (data, err) => {
      if(data.data){
        let params = {
          rd_session: app.globalData.userInfo.rd_session,
          card_id: id
        }
        $.httpPost("applay_recharge_card", params, (data, err) => {
          if (data.result == "success") {
            //去支付
            app.wxpay_recharge(data.data.order_no, app.globalData.userInfo.openId);
          }
        })
      }else{
        this.setData({
          showeditdialog: true,
          czid:id
        })
      }
    })
   
  },
  tolist(e){
    var id = e.target.dataset.id
    wx.navigateTo({
      url: '/pages/mine/ymlist?id='+id,
    })
  },
  formSubmit: function (e) {
    if (!app.check_empty(e.detail.value.pwd)) {
      var rd_session = wx.getStorageSync('rd_session');
      var param = { rd_session: rd_session, pass: e.detail.value.pwd}
      $.httpPost("edit_pass", param, (data, err) => {
        if(data.result == 'success'){
          this.setData({
            showeditdialog: false
          })
          wx.showToast({
            title: data.message,
            duration: 2000
          })
          this.chongz(this.data.czid)
        }
      })
    } else {
      wx.showToast({
        title: '有信息没有填写哦~',
        duration: 2000
      })
    }
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },
  formReset: function () {
    this.setData({
      showeditdialog: false
    })
    console.log('form发生了reset事件')
  },
  editpwd(){
    this.setData({
      showeditdialog:true
    })
  }
    
})  